﻿using Sixeyed.CodeGeneration.Metadata;
using Sixeyed.CodeGeneration.Metadata.Interfaces;

namespace Sixeyed.Guidance.CodeGeneration.CodeGeneration
{
    /// <summary>
    /// Represents currently selected metadata 
    /// </summary>
    public class Metadata
    {
        public delegate void SelectedProviderChangedHandler(object sender);
        public event SelectedProviderChangedHandler SelectedProviderChanged;

        private IMetadataProvider _provider;

        /// <summary>
        /// Gets/sets the metadata provider
        /// </summary>
        public IMetadataProvider Provider
        {
            get { return _provider; }
            set
            {
                this._provider = value;
                if (this.SelectedProviderChanged != null)
                {
                    this.SelectedProviderChanged(this);
                }

            }
        }

        /// <summary>
        /// Sets the metadata source
        /// </summary>
        /// <param name="sourceConfiguration">Metadata source configuration</param>
        public void SetSource(SourceConfiguration sourceConfiguration)
        {
            IMetadataSource source = SourceContainer.GetSource(sourceConfiguration.SourceName);
            source.Uri = sourceConfiguration.SourceUri;
            this.Provider = source.GetProvider(sourceConfiguration.ProviderName);
        }
    }
}
